package app.repositories.impl;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import app.models.BiometriaTemplate;
import app.repositories.BiometriaTemplateRepository;
import app.repositories.Repository;
import app.util.Constants;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class BiometriaTemplateRepositoryImpl extends Repository<BiometriaTemplate, Long> implements BiometriaTemplateRepository{

	protected BiometriaTemplateRepositoryImpl(EntityManager entityManager) {
		super(entityManager);
	}

	public BiometriaTemplate findBiometriaTemplateByPacienteId(Integer id){
		Criteria criteria = super.createCriteria();
		
		criteria.add(Restrictions.eq(Constants.ID_PACIENTE, id));
		
		return (BiometriaTemplate) criteria.uniqueResult();
	}
	
	public BiometriaTemplate findBiometriaTemplateByPacienteIdAndByFinger(Integer id, String finger){
		Criteria criteria = super.createCriteria();
		
		criteria.add(Restrictions.eq(Constants.ID_PACIENTE, id));
		criteria.add(Restrictions.eq(Constants.FINGER, finger));
		
		return (BiometriaTemplate) criteria.uniqueResult();
	}
	
}
